﻿@{
    ViewBag.Title = "404-Lan // Forside - Nyheder";
}

@model LanHomepage.ViewModels.MainViewModel


<section class="view">
    <div class="news-headline">
        <h1>Nyhedsoversigt</h1>
    </div>

    @if (User.IsInRole("Admin")) 
    { 
        <div class="new-post">
            <button id="new-news-button">Create news</button>
        </div>
    }

    <div class="news-posts">

        @if (User.IsInRole("Admin")) 
        {
            using (Html.BeginForm("NewsUpload", "Main", FormMethod.Post, new { enctype = "multipart/form-data" }))
            {
                <div class="new-news-wrapper">                
                    <input type="text" name="headline"/>
                    <textarea name="news_text"></textarea>
                    <button type="submit">OK</button>
                </div>
            }
        }

        @foreach (var newsPost in Model.NewsPosts)
        {
            
            <div id="@newsPost.Id" class="news-wrapper">
                <div class="news-line"></div>



 
                <h2 class="news-post-headline">@newsPost.Headline</h2>
                <h2 class="news-post-date">Posted: @newsPost.Date</h2>
                <p class="news-post-message">@newsPost.Message</p>
                <br />

                        @if (User.IsInRole("Admin")) 
                        {
                            <img class="edit-news-post" src="~/Images/Icons/edit_16x16.png" />
                            <img class="delete-news-post" src="~/Images/Icons/delete_16x16.gif" />
                            
                            <div class="edit-news-wrapper">                
                                <input class="edit-news-headline" type="text" name="headline"/>
                                <textarea class="edit-news-message" name="news_text"></textarea>
                                <button class="edit-news-ok">OK</button>
                                <button class="edit-news-cancel">Cancel</button>
                            </div>
                        }
            </div>
        }
    </div>
</section>
